home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 3.7 KB | 129 lines | [TEXT/MPS ] |
- // UAssociation.h
- // Copyright © 1988-96 by Apple Computer, Inc. All rights reserved.
-
- #ifndef __UASSOCIATION__
- #define __UASSOCIATION__
-
- // MacApp
-
- #ifndef __ULIST__
- #include "UList.h"
- #endif
-
- //----------------------------------------------------------------------------------------
- // Forward and external class declarations.
- //----------------------------------------------------------------------------------------
-
- class TEntry;
- class TEntriesList;
-
-
- //----------------------------------------------------------------------------------------
- // TEntry: This class associates a key CString with a value CString.
- //----------------------------------------------------------------------------------------
-
- class TEntry : public TObject
- {
- MA_DECLARE_CLASS;
-
- public:
- CStringHandle fKey; // A handle to the 'keyStr'
-
- CStringHandle fValue; // A handle to the 'valueStr'
-
- TEntry();
- // Constructor
-
- void IEntry(const CStr255& itsKey, const CStr255& itsValue);
- // Initialization routine
-
- virtual ~TEntry();
- // Frees the fKey & fValue CString handles then calls Inherited::Free
-
- virtual void SetValue(const CStr255& value);
- // Sets the fValue field to theValue
-
- };
-
-
- //----------------------------------------------------------------------------------------
- // TEntriesList: Subclass of TSortedList that manages a sorted list of TEntry objects,
- // used as an instance variable in TAssociation
- //----------------------------------------------------------------------------------------
-
- class TEntriesList : public TSortedList
- {
- MA_DECLARE_CLASS;
-
- public:
- TEntriesList();
- // Empty constructor to satisfy compiler.
- virtual ~TEntriesList();
- // Destructor
-
- void IEntriesList();
- // Initialize the list
-
- virtual CompareResult Compare(TObject* item1, TObject* item2);
- // Compares 'item'1 with 'item2' returning an integer indicating the results of
- // the comparison
-
- };
-
-
- //----------------------------------------------------------------------------------------
- // TAssociation: This class is used to create lists of strings that are accessed via their
- // associated keys. The keys & strings are stored in TEntry objects which are in the
- // TEntriesList instance variable
- //----------------------------------------------------------------------------------------
-
- class TAssociation : public TObject
- {
- MA_DECLARE_CLASS;
-
- public:
- TEntriesList* fEntries; // The list of TEntries that stores the
- // associations
-
-
- TAssociation();
- // Constructor
-
- void IAssociation();
- // Initialization routine
-
- virtual ~TAssociation();
- // Frees the instance variable fEntries
-
- virtual Boolean ValueAt(const CStr255& keyStr, CStr255& valueStr);
- // Given 'keyStr' returns the associated CString in 'valueStr', with the result
- // true if an associated CString was found
-
- virtual Boolean KeyAt(const CStr255& valueStr, CStr255& keyStr);
- // Given 'valueStr' returns the associated key in 'keyStr', with the result true
- // if an associated key was found
-
- virtual TEntry* EntryWithKey(const CStr255& keyStr);
- // Returns the Entry containing 'keyStr'
-
- virtual TEntry* EntryWithValue(const CStr255& valueStr);
- // Returns the entry containing 'valueStr'
-
- virtual void InsertEntry(const CStr255& keyStr, const CStr255& valueStr);
- // Inserts an entry into thei association, if 'keyStr' already exists then the
- // value is merely replaced with 'valueStr'. Otherwise a new Entry is created with
- // the above 'keyStr' and 'valueStr'
-
- virtual void RemoveValueAt(const CStr255& keyStr);
- // Removes the value associated with 'keyStr'
-
- virtual void RemoveKeyAt(const CStr255& valueStr);
- // Removes the key associated with 'valueStr'
-
- };
-
-
- #endif
-
-
-